import { defineBoot } from '#q-app/wrappers'

/**
 * 输入框聚焦时选中所有文本
 */
const selectAllText = {
  mounted(el: HTMLElement) {
    const input = el.querySelector('input') as HTMLInputElement
    input?.addEventListener('focus', () => {
      if (input.value.length > 0) {
        // 选中所有文本
        input.select()
      }
    })
  },
}

export default defineBoot(({ app }) => {
  app.directive('select-all-text', selectAllText)
})

export { selectAllText }
